package com.dingqb.mycs.ui.adapter;

import java.util.List;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.dingqb.mycs.R;
import com.dingqb.mycs.ui.entity.HistoryEntity;

/**
 * 
 * 
 */
public class HistoryTodayListAdapter extends BaseAdapter {
	private LayoutInflater mInflater; // 得到一个LayoutInfalter对象用来导入布局
	private List<HistoryEntity> list;

	public HistoryTodayListAdapter(Context context, List<HistoryEntity> list) {
		this.list = list;
		this.mInflater = LayoutInflater.from(context);
	}

	@Override
	public int getCount() {
		return list == null ? 0 : list.size();
	}

	@Override
	public Object getItem(int position) {
		return list == null ? 0 : list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {

		ViewHolder holder;
		// 观察convertView随ListView滚动情况
		Log.v("MyListViewBase", "getView " + position + " " + convertView);
		if (convertView == null) {
			convertView = mInflater.inflate(R.layout.item_historytoday, null);
			holder = new ViewHolder();
			/** 得到各个控件的对象 */
			holder.title = (TextView) convertView.findViewById(R.id.tv_title);
			holder.calendar = (TextView) convertView
					.findViewById(R.id.tv_calendar);
			holder.calendarChinese = (TextView) convertView
					.findViewById(R.id.tv_calendar_chinese);
			holder.desc = (TextView) convertView.findViewById(R.id.tv_desc);
			convertView.setTag(holder);// 绑定ViewHolder对象
		} else {
			holder = (ViewHolder) convertView.getTag();// 取出ViewHolder对象
		}
		/** 设置TextView显示的内容，即我们存放在动态数组中的数据 */

		holder.title.setText(list.get(position).getTitle());
		holder.calendar.setText(list.get(position).getYear() + "年"
				+ list.get(position).getMonth() + "月"
				+ list.get(position).getDay() + "日");
		holder.calendarChinese.setText(list.get(position).getLunar());
		holder.desc.setText(list.get(position).getDes());
		return convertView;
	}

	/** 存放控件 */
	public final class ViewHolder {

		public TextView title;
		public TextView calendar;
		public TextView calendarChinese;
		public TextView desc;
	}

}
